package modelz;

import modelz.latebinding.LateBindingHelper;
import modelz.latebinding.LateBindingListener;
import modelz.latebinding.LateBindingProvider;


/**
 * Subclasses contain an ID of a comparable type.
 * 
 * @author mkl
 */
public abstract class UpdateableAction<A extends UpdateableAction<A,T>, T extends Updateable<T>> extends
		Updateable<A> {

	private T item;

	protected UpdateableAction(LateBindingProvider<T> provider) {
		LateBindingHelper.performLateBinding(provider, new LateBindingListener<T>(){
			public void bound(T boundItem) {
				item = boundItem;
				item.addListener(new UpdateListener<T>() {
					public void updated(T item) {
						// just pass it on
						update();
					}
				});
				update();	// TODO let update take place in addListener?
			}});
	}

	protected T getItem() {
		return item;
	}
	
	public abstract String getCaption();

	public abstract boolean canPerform();

	public abstract void perform();

}
